//导入node:fs模块
import fs from 'node:fs'
import { Version } from './components/index.js'

//输出提示
logger.info(`---------------(๑•̀ㅂ•́)و✧---------------`)
logger.info(`Menu plugin插件${Version.version}载入成功`)
logger.info(`作者-lingran7031 2024.10.6`)

const files = fs.readdirSync('./plugins/menu-plugin/apps').filter(file => file.endsWith('.js'))

let ret = []

files.forEach((file) => {
  ret.push(import(`./apps/${file}`))
})

ret = await Promise.allSettled(ret)

let apps = {}
for (let i in files) {
  let name = files[i].replace('.js', '')

  if (ret[i].status != 'fulfilled') {
      logger.error(`载入插件错误：${logger.red(name)}`)
      logger.error(ret[i].reason)
      continue
  }
  apps[name] = ret[i].value[Object.keys(ret[i].value)[0]]
}

export { apps }